package com.tz.entity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.*;

/**
 * Created by YEJF on 2017/1/6.
 */
@Component
public class Host { //主机类

    private Long id; //主键

    @Autowired
    @Qualifier(value = "ssd")
    private List<HardDisk> disks; //硬盘

    @Autowired
    private MainBoard board; //主板

    @Autowired
    private CPU cpu; //

//    @Autowired
//    @Qualifier(value = "mockMemories")
    @Resource  //此处将根据名字来查询 bean, 而这个名为 memories的集合Bean是通过 某个类中加了@Bean注解的方法提供的
    private Set<Memory> memories; //内存

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<HardDisk> getDisks() {
        return disks;
    }

    public void setDisks(List<HardDisk> disks) {
        this.disks = disks;
    }

    public MainBoard getBoard() {
        return board;
    }

    public void setBoard(MainBoard board) {
        this.board = board;
    }

    public CPU getCpu() {
        return cpu;
    }

    public void setCpu(CPU cpu) {
        this.cpu = cpu;
    }

    public Set<Memory> getMemories() {
        return memories;
    }

    public void setMemories(Set<Memory> memories) {
        this.memories = memories;
    }

    @PostConstruct  // 在构造方法之后，执行此方法完成初始化
    private void afterConstruct() {
        //给属性赋值
        List<HardDisk> disks = new ArrayList<>();
        Ssd s1 = new Ssd(128,"浦科特",SsdType.MLC);
        Hdd h1 = new Hdd(500, "希捷", 7200);
        //
        disks.add(s1);
        disks.add(h1);
        //
        this.disks = disks;
    }
}

